﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace ThermalImagery.showForms
{
    public partial class FrmPieChart : UIForm
    {
        public FrmPieChart()
        {
            InitializeComponent();

            var option = new UIPieOption();

            //设置Title
            option.Title = new UITitle();
            option.Title.Text = "除雾加热检测结果";
            //option.Title.SubText = "副标题";
            option.Title.Left = UILeftAlignment.Center;

            //设置ToolTip
            option.ToolTip.Visible = true;

            //设置Legend
            option.Legend = new UILegend();
            option.Legend.Orient = UIOrient.Vertical;
            option.Legend.Top = UITopAlignment.Top;
            option.Legend.Left = UILeftAlignment.Left;

            option.Legend.AddData("NG", Color.FromArgb(255, 128, 128));
            option.Legend.AddData("OK", Color.FromArgb(80, 158, 254));

            //设置Series
            var series = new UIPieSeries();
            series.Name = "NG/OK";
            series.Center = new UICenter(50, 55);
            series.Radius = 70;
            series.Label.Show = true;

            //增加数据
            series.AddData("NG", 0, Color.FromArgb(255, 128, 128));
            series.AddData("OK", 0, Color.FromArgb(80, 158, 254));


            //增加Series
            option.Series.Clear();
            option.Series.Add(series);

            //设置Option
            uiPieChart1.SetOption(option);
            //uiPieChart1.ChartStyleType = UIChartStyleType.Plain;
        }

        public class Info
        {
            public static int OK_COUNT { get; set; }
            public static int NG_COUNT { get; set; }
        }

        private void FCombobox_Load(object sender, EventArgs e)
        {
            uiPieChart1.Update("NG/OK", "NG", Info.NG_COUNT);
            uiPieChart1.Update("NG/OK", "OK", Info.OK_COUNT);

            uiPieChart1.Refresh();
            double PercentNG = Convert.ToDouble(Info.NG_COUNT) / Convert.ToDouble(Info.NG_COUNT + Info.OK_COUNT);       
            string ResultNG = PercentNG.ToString("0.00%");//得到50.0%
            double PercentOK = Convert.ToDouble(Info.OK_COUNT) / Convert.ToDouble(Info.NG_COUNT + Info.OK_COUNT);
            string ResultOK = PercentOK.ToString("0.00%");//得到50.0%
            labelNG.Text = ResultNG;
            labelOK.Text = ResultOK;
        }
    }
}
